<?php 
class GoodsTypeController extends AuthController{
	public $db;
	public $goods_type;
	public $cat_id;

	public function __init(){
		//商品类型的扩展模型
		$this->db=K('GoodsType');
		$this->goods_type=S('goods_type');
		$this->cat_id=Q('cat_id',0,'intval');
		//当有商品类型id，但是没有该商品类型时不进行后续操作
		if($this->cat_id && !isset($this->goods_type[$this->cat_id])){
			$this->error('商品类型不存在');
		}
	}

	public function index(){
		$this->assign('goods_type',$this->goods_type);
		$this->display();
	}
	//更新缓存
	public function upCache(){
		if($this->db->updateCache()){
			$this->success('缓存更新成功','index');
		}else{
			$this->error($this->db->error);
		}
	}
	//添加
	public function add(){
		if(IS_POST){
			if($this->db->addGoodsType()){
				$this->success('类型添加成功','index');
			}else{
				$this->error($this->db->error);
			}
		}else{			
			$this->display();
		}
	}
	//编辑
	public function edit(){
		if(IS_POST){
			if($this->db->editGoodsType()){
				$this->success('类型编辑成功','index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			$this->assign('field',$this->goods_type[$this->cat_id]);
			$this->display();
		}
	}
	//删除
	public function del(){
		if($this->db->delGoodsType()){
			$this->success('商品类型删除成功','index');
		}else{
			$this->error($this->db->error);
		}
	}

}

?>